home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 34.zip / BS1 part 34 / Weubblers handler.adf / examples / DiskResource.c < prev    next >
C/C++ Source or Header  |  1988-12-16  |  2KB  |  96 lines

  1. #include <resources/disk.h>
  2.  
  3. struct DiscResource *DiskResource;
  4. struct DiscResourceUnit DiskResourceUnit;
  5. struct MsgPort *replyport;
  6.  
  7. #asm
  8.  
  9. _AllocUnit:
  10.     move.l    4(sp),d0
  11.     movea.l    _DiskResource,a6
  12.     jmp        -6(a6)
  13.  
  14. _FreeUnit:
  15.     move.l    4(sp),d0
  16.     movea.l    _DiskResource,a6
  17.     jmp        -12(a6)
  18.  
  19. _GetUnit:
  20.     movea.l    4(sp),a1
  21.     movea.l    _DiskResource,a6
  22.     jmp        -18(a6)
  23.  
  24. _GiveUnit:
  25.     movea.l    _DiskResource,a6
  26.     jmp        -24(a6)
  27.  
  28. _GetUnitId:
  29.     move.l    4(sp),d0
  30.     movea.l    _DiskResource,a6
  31.     jmp        -30(a6)
  32.  
  33.     public    _DummyInterrupt
  34.     public    _AllocUnit
  35.     public    _FreeUnit
  36.     public    _GetUnit
  37.     public    _GiveUnit
  38.     public    _GetUnitId
  39.  
  40. #endasm
  41.  
  42. Dummy()
  43. {
  44. #asm
  45. _DummyInterrupt:
  46.     movem.l    d0-d7/a0-a6,-(sp)
  47. #endasm
  48.     kprintf("hallo\n");
  49. #asm
  50.     movem.l    (sp)+,d0-d7/a0-a6
  51.     rts
  52. #endasm
  53. }
  54.  
  55. struct MsgPort *CreatePort();
  56. struct DiscResource *OpenResource();
  57. extern void DummyInterrupt();
  58. extern struct DiscResourceUnit *GetUnit();
  59. struct DiscResourceUnit *FormerUnit;
  60.  
  61. InitDiskRes()
  62. {
  63.  replyport=CreatePort("replyport",0);
  64.  DiskResourceUnit.dru_Message.mn_Node.ln_Type=NT_MESSAGE;
  65.  DiskResourceUnit.dru_Message.mn_ReplyPort=replyport;
  66.  DiskResourceUnit.dru_DiscBlock.is_Code=DummyInterrupt;
  67.  DiskResourceUnit.dru_DiscSync.is_Code=DummyInterrupt;
  68.  DiskResourceUnit.dru_Index.is_Code=DummyInterrupt;
  69.  DiskResource=OpenResource(DISKNAME,0);
  70. }
  71.  
  72. FinishDiskRes()
  73. {
  74.  if (replyport) DeletePort(replyport);
  75. }
  76.  
  77. GiveMeTheDisks()
  78. {
  79.  do
  80.  {
  81.  FormerUnit=GetUnit(&DiskResourceUnit);
  82.  if (FormerUnit==0) 
  83.   {WaitPort(replyport);
  84.    GetMsg(replyport);}
  85.  }
  86.  while (FormerUnit==0);
  87. }
  88.  
  89. GiveBackTheDisks()
  90. {
  91.  Disable();
  92.  GiveUnit();
  93.  Enable();
  94. }
  95.  
  96.